<meta charset="UTF-8">
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php
session_start();
include("conn/conn.php");

$conn = prepare();

if(@$_SESSION['username']==""){
  echo "<script>alert('请先登录后购物!');history.back();</script>"; 
  exit;
 }
 
$book_id = $_GET['book_id'];

$id=strval($_GET['book_id']);
$sql= exectue_sql_statement($conn, "select * from Store where book_id=$book_id"); 
$info=sqlsrv_fetch_array($sql);
if($info['book_amount']<=0){
   echo "<script>alert('该商品已经售完!');history.back();</script>";
   exit;
 }
  $array=explode("@",$_SESSION['booklist']);
  for($i=0;$i<count($array)-1;$i++){
	 if($array[$i]==$id){
	     echo "<script>alert('该商品已经在您的购物车中!');history.back();</script>";
		 exit;
	  }
	}
  $_SESSION['booklist']=$_SESSION['booklist'].$id."@";
  $_SESSION['quantity']=$_SESSION['quantity']."1@";
  header("location:cart.php");
?> 